package com.yellow.car.impl;

import com.yellow.car.api.PathApi;
import com.yellow.car.request.PathQueryRequest;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.HashMap;

@Service
@Slf4j
public class PathApiImpl implements PathApi {
    private static final HashMap<String, int[][]> pathHashMap = new HashMap<>();

    @Override
    public void setPath() {
        int[][] acPathLocation = new int[][]{{1, 1}, {2, 1}, {3, 1}, {4, 1}, {4, 2}, {4, 3}};
        int[][] abPathLocation = new int[][]{{1, 1}, {1, 2}, {1, 3}, {1, 4}, {1, 5},
                {2, 5}, {3, 5}, {4, 5}, {5, 5}, {6, 5}, {6, 6}, {6, 7}, {7, 7}, {8, 7}, {8, 8}};
        int[][] bcPathLocation = new int[][]{{8, 8}, {8, 7}, {8, 6}, {8, 5}, {8, 4}, {8, 3},
                {7, 3}, {6, 3}, {5, 3}, {4, 3}};
        pathHashMap.put("AC", acPathLocation);
        pathHashMap.put("AB", abPathLocation);
        pathHashMap.put("BC", bcPathLocation);
        //此处只考虑什么时候释放,所以AC和CA路径一样,其他类似
        pathHashMap.put("CA", acPathLocation);
        pathHashMap.put("BA", abPathLocation);
        pathHashMap.put("CB", bcPathLocation);
    }

    @Override
    public int[][] getPath(PathQueryRequest request) {
        String key = request.getStartStation() + request.getEndStation();
        return pathHashMap.get(key);
    }
}
